package com.baturu.vin.honda.transformer;

import com.baturu.kit.kit.function.SafeFunction;
import com.baturu.vin.dto.superEPC.SEPCCarTypeDTO;
import com.baturu.vin.dto.superEPC.SEPCCarTypeDetailDTO;
import com.baturu.vin.dto.superEPC.SEPCExtendAttributeDTO;
import com.baturu.vin.honda.dto.HondaVinInfoDTO;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: chenjiahao
 * @Time: 2019/5/7
 */
public class SEPCCarTypeTransformer {

    public static final SafeFunction<HondaVinInfoDTO, SEPCCarTypeDTO> VIN_INFO_TO_MULTI_HMODTYP_SEPC_CAR_TYPE = input ->
            SEPCCarTypeDTO.builder()
                    .vinCode(input.getVinCode())
                    .superAnalyserName("honda")
                    .carTypeDetailDTOList(Lists.newArrayList(
                            SEPCCarTypeDetailDTO.builder()
                                    .code("remark")
                                    .desc("选择设备")
                                    .subValue(input.getReMarkList()).build()))
                    .extendAttrDTOs(Lists.newArrayList(
                            SEPCExtendAttributeDTO.builder().code("disk").value(input.getDisk()).build(),
                            SEPCExtendAttributeDTO.builder().code("hmodtyp").value(input.getHmodtyp()).build()))
                    .build();


    public static final SafeFunction<HondaVinInfoDTO, SEPCCarTypeDTO> VIN_INFO_TO_MULTI_SEPC_CAR_TYPE = input ->
            SEPCCarTypeDTO.builder()
                    .vinCode(input.getVinCode())
                    .superAnalyserName("honda")
                    .carTypeDetailDTOList(Lists.newArrayList(
                            SEPCCarTypeDetailDTO.builder()
                                    .desc("选择等级/变速箱")
                                    .code("multiCarType")
                                    .subValue(Lists.newArrayList(
                                            SEPCCarTypeDetailDTO.builder().code("carea").desc("地区").value(input.getCarea()).build(),
                                            SEPCCarTypeDetailDTO.builder().code("ctrsmtyp").desc("变速箱").value(input.getCtrsmtyp()).build(),
                                            SEPCCarTypeDetailDTO.builder().code("xgradefulnam").desc("级别").value(input.getXgradefulnam()).build()))
                                    .build()
                    ))
                    .extendAttrDTOs(Lists.newArrayList(SEPCExtendAttributeDTO.builder().code("disk").value(input.getDisk()).build()))
                    .build();

    public static final SafeFunction<HondaVinInfoDTO, SEPCCarTypeDTO> VIN_INFO_TO_SEPC_CAR_TYPE = input ->
            SEPCCarTypeDTO.builder()
                    .superAnalyserName("honda")
                    .brandName(input.getBtrBrand())
                    .vinCode(input.getVinCode())
                    .btrId(input.getBtrId())
                    .area(input.getCarea())
                    .carSystem(input.getCmodnamepc())
                    .transmissionType(input.getCtrsmtyp())
                    .engineType(input.getNengnpf())
                    .carType(input.getXgradefulnam())
                    .year(input.getDmodyr())
                    .bodyModel(input.getXcardrs())
//                    .showCarType(input.getCmodnamepc() + " " + input.getXcardrs() + " " + input.getDmodyr() + " " + input.getCarea())
                    .showCarType(input.getBtrBrand()+" "+(StringUtils.isBlank(input.getCarSystem()) ? input.getCmodnamepc() : input.getCarSystem() )+ " " + input.getDmodyr())
                    .carTypeDetailDTOList(Lists.newArrayList(SEPCCarTypeDetailDTO.builder()
                            .desc("车辆重要数据")
                            .code("carDetail")
                            .subValue(Lists.newArrayList(
                                    SEPCCarTypeDetailDTO.builder().desc("VIN(车架号)")
                                            .value(input.getVinCode())
                                            .build(),
                                    SEPCCarTypeDetailDTO.builder().desc("车型").value(input.getCmodnamepc()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("级别").value(input.getXgradefulnam()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("车门").value(input.getXcardrs()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("年份").value(input.getDmodyr()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("地区").value(input.getCarea()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("变速箱").value(input.getCtrsmtyp()).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("发动机生产序号").value("").build(),
                                    SEPCCarTypeDetailDTO.builder().desc("车内颜色类型").value("").build(),
                                    SEPCCarTypeDetailDTO.builder().desc("变速箱系列号").value("").build(),
                                    SEPCCarTypeDetailDTO.builder().desc("车外HES颜色").value("").build(),
                                    SEPCCarTypeDetailDTO.builder().desc("车架生产序号").value(input.getVinCode().substring(9, 17)).build(),
                                    SEPCCarTypeDetailDTO.builder().desc("设备").value(CollectionUtils.isEmpty(input.getRemark()) ? "" : String.join(" ", input.getRemark())).build()
                            )).build()))
                    .extendAttrDTOs(Lists.newArrayList(
                            SEPCExtendAttributeDTO.builder().code("disk").value(input.getDisk()).build(),
                            SEPCExtendAttributeDTO.builder().code("npl").value(input.getNpl()).build(),
                            SEPCExtendAttributeDTO.builder().code("hmodtyp").value(input.getHmodtyp()).build()
                    ))
                    .build();
}
